package com.spoplar.test;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;

public class QueueConsumer {

	private static final String USER = ActiveMQConnection.DEFAULT_USER;
	private static final String PASSWORD = ActiveMQConnection.DEFAULT_PASSWORD;
	private static final String BROKER_URL = ActiveMQConnection.DEFAULT_BROKER_URL;
	
	
	public static void main(String[] args) throws JMSException {
		
	    ActiveMQConnectionFactory connectionFactory = 	new ActiveMQConnectionFactory(USER,PASSWORD,BROKER_URL);
		connectionFactory.setTrustAllPackages(true);
		
	    Connection connection = connectionFactory.createConnection();
	    connection.start();
	    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
	    Destination destination = session.createQueue("hello");
	    MessageConsumer consumer = session.createConsumer(destination);
	    //TextMessage txmessage = (TextMessage) consumer.receive();
	    //String str = txmessage.getText();
	    
	   // System.out.println(str);
	    
	    
//	    while(true){
//	    	TextMessage txmMessage = (TextMessage)consumer.receive();
//	    	String str = txmMessage.getText();
//	    	System.out.println(str);
//	    }
	    
	    consumer.setMessageListener(new QueueListener());
	    
	    
	}
	
	
}
